package com.example.pages;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class HomePage extends InternalPage {

	@FindBy(css = "#results a")
	public List<WebElement> filmsRows;

	public FilmsPage selectExistFilm(String filmName) {
		for (WebElement row: filmsRows){
			if (convertListToName(row).equals(filmName)){
				row.click();
				break;
			};
		}
		return MyPageFactory.getPage(driver, FilmsPage.class);
	}
	
	public HomePage selectNotExistFilm(String filmName) {
		for (WebElement row: filmsRows){
			if (convertListToName(row).equals(filmName)){
				row.click();
				break;
			};
		}
		return MyPageFactory.getPage(driver, HomePage.class);
	}
	
	private String convertListToName(WebElement row) {
		return row.findElement(By.tagName("div")).findElement(By.className("title")).getText();
		
	}
}
